/*-//GEN-BEGIN:copyright
 * ForBILE - Framework for Building Interactive Learning Environments
 * Computing Institute - Federal University of Alagoas - Brazil
 * Group of Otimization of the Web
 *
 * Copyright (C) 2007 Ig Bittencourt (ig.ibert@gmail.com)
 *		      Camila Nunes (camilapbnunes@hotmail.com)
 *	              Marcos Tadeu (zero.ufal@gmail.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *///GEN-END:copyright
package br.ufal.ic.forbile.agents.persistence;

import br.ufal.ic.forbile.agents.ForBILEAgent;
import br.ufal.ic.forbile.agents.persistence.behaviours.SensorPersistence;
import br.ufal.ic.forbile.log.PersistenceOWLLog;
import br.ufal.ic.utils.Constants;
import br.ufal.ic.utils.RegionServer;
import br.ufal.ic.utils.SharedMem;
import jade.core.AID;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.util.logging.Logger;

/**
 * PersistenceAgent1.java
 *
 * <p>A full description of this class.
 *
 * @see ForBILEAgent.
 *
 * @author <a href="mailto:ig.ibert@gmail.com">ig</a>.
 * @author <a href="mailto:camilapbnunes@hotmail.com">camila</a>.
 * @since 0.1
 * @version 0.1
 *
 */
public abstract class PersistenceAgent extends ForBILEAgent {
    
    // Constants -----------------------------------------------------
    
    // Attributes ----------------------------------------------------
    
    /**
     * Attribute to get the persistence OWL configuration
     */
    protected PersistenceOWLLog persistenceOWLLog;
    
    // Static --------------------------------------------------------
    
    private static Logger logger;
    
    static {
        logger = Logger.getLogger(PersistenceAgent.class.getName());
    }
    
    // Constructors --------------------------------------------------
    
    /**
     * Creates a new instance of PersistenceAgent1
     * @param containerName the jade container name
     * @param agentLocalName the agent local name
     */
    public PersistenceAgent(final String containerName, final String agentLocalName) {
        super(containerName, agentLocalName);
        this.persistenceOWLLog = new PersistenceOWLLog();
    }
    
    // Public --------------------------------------------------------
    /**
     * Methods to implement of the persistence agent.
     */
    public abstract void create(final AID receiver);
    /**
     * Deletes the specific content
     */
    public abstract void delete(final AID receiver);
    /**
     * Retrieves the specific content
     * @param receiver the receiver AID agent
     */
    public abstract void retrieve(final AID receiver);
    /**
     * Updates the specific content
     */
    public abstract void update(final AID receiver);
    
    // ForBILEAgent implementation ------------------------------------
    
    protected void sensor() {
        addBehaviour(new SensorPersistence(this, SENSOR_TIME));
    }
    
    // Y overrides ---------------------------------------------------
    
    // Package protected ---------------------------------------------
    
    // Protected -----------------------------------------------------
    
    /**
     * Gets the PersistenceOWLLog of the critical region.
     *
     * @return PersistenceOWLLog of the critical region.
     */
    protected PersistenceOWLLog getPersistenceOWLLog() {
        try {
            SharedMem mem = (SharedMem) Naming.lookup(RegionServer.HOST_URL);
            this.persistenceOWLLog = (PersistenceOWLLog) mem.
                    getRegion(Constants.OWLPersistence).retrieveIfExist(this.persistenceOWLLog);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return persistenceOWLLog;
    }
    
    // Private -------------------------------------------------------
    
    // Inner classes -------------------------------------------------
    
}
